package com.aditya.videoutil.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

import org.apache.commons.io.IOUtils;

public class Compressor {

  public static void compress(File input, File output) throws IOException {
    FileInputStream fis = null;
    FileOutputStream fos = null;
    GZIPOutputStream gzipStream = null;
    try {
      fis = new FileInputStream(input);
      fos = new FileOutputStream(output);
      gzipStream = new GZIPOutputStream(fos);
      IOUtils.copy(fis, gzipStream);
    } finally {
      if (gzipStream != null)
        gzipStream.close();
      if (fis != null)
        fis.close();
      if (fos != null)
        fos.close();
    }

  }

  public static void decompress(File input, File output) throws IOException {
    FileInputStream fis = null;
    FileOutputStream fos = null;
    GZIPInputStream gzipStream = null;
    try {
      fis = new FileInputStream(input);
      fos = new FileOutputStream(output);
      gzipStream = new GZIPInputStream(fis);
      IOUtils.copy(gzipStream, fos);
    } finally {
      if (gzipStream != null)
        gzipStream.close();
      if (fis != null)
        fis.close();
      if (fos != null)
        fos.close();
    }
  }

}
